package com.gifts.ui.page.selectaProduct;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Panel;
import java.util.List;

import javax.swing.JRootPane;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import com.gifts.service.FacebookService;
import com.gifts.service.GoogleShoppingService;
import com.gifts.service.client.GoogleShoppingClient;
import com.gifts.service.entity.FacebookUser;
import com.gifts.service.entity.GoogleProduct;
import com.gifts.service.entity.GoogleShoppingObj;
import com.gifts.ui.page.common.JMainPanel;
import com.gifts.ui.page.common.JThumbnail;
import com.gifts.ui.page.common.JThumbnailPanel;
import com.gifts.ui.page.common.Page;
/**
 * MainClass for displaying product page
 * @author kevin
 *
 */

public class SelectAProductPage extends Page {

	/**
	 * A service for facebook
	 */
	private FacebookService facebookService = FacebookService.getInstance();
	
	private GoogleShoppingService googleShoppingService = GoogleShoppingService.getInstance();
	private JMainPanel mainPanel;
	
	
	
	/**
	 * listSuggestionPanel
	 */
	private JSelectAProductPanel selectAProductPanel;
	
	
	
	

	public SelectAProductPage(Composite parent, int style) {

		super(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
		init();
		
		
	

	}
	
	public void init() {
		/* Create and setting up frame */
		Frame frame  = SWT_AWT.new_Frame(this);

		setSize(new Point(800, 600));
		Panel panel = new Panel(new BorderLayout()) {
			public void update(java.awt.Graphics g) {
				/* Do not erase the background */
				paint(g);
			}
		};

		frame.add(panel);
		JRootPane root = new JRootPane();

		panel.add(root);
		java.awt.Container contentPane = root.getContentPane();
		BorderLayout borderLayout = new BorderLayout();
		
		contentPane.setLayout(borderLayout);

		selectAProductPanel = new JSelectAProductPanel();
		
		mainPanel = new JMainPanel();
		
		contentPane.add(mainPanel,BorderLayout.NORTH);
		
		contentPane.add(selectAProductPanel,BorderLayout.CENTER);
		
		
	}
	


	public void loadListSuggestionPanel(FacebookUser user) {
		try {
			
			List<FacebookUser> upcomingBirthdayFriends = facebookService.findUpcomingBirthdays(30);
			JListInterestsPanel upcomingBirthdayPanel = selectAProductPanel.getJListInterestsPanel();
		
			
		
			
		
			
		} catch(Exception e) {
			e.printStackTrace();
		}
		

		
		
	}
	
	
	
	
	public void loadListProductsPanel(String query) {
		try {
			GoogleShoppingObj googleShoppingObj = googleShoppingService.find(query,null,null);
			JListProductsPanel jListProductPanel = selectAProductPanel.getJListProductPanel();
			JThumbnailPanel thumnailPanel = jListProductPanel.getJThumbnailPanel();
//			for(GoogleProduct product: googleShoppingObj.getProducts()) {
//				String thumbnailUrl = product.getImageLink();
//				String name = product.getTitle();
//				thumnailPanel.addJThumbnail(new JThumbnail(thumbnailUrl,name));
//			}
		
			thumnailPanel.repaint();
			thumnailPanel.revalidate();
			
		} catch(Exception e) {
			
		}
		
	
	}
}
